function AccountController(model, view) {
	this.model = model;
	this.view = view;
	
	var ac = this;
	
        
	this.init = function() {
            //this.model.loadRoles(roles);
            $('#account_save_action').click(function() {
                    ac.saveAccount(this);
            });
            $('.role_action').click(function() {
                    ac.changeRole(this);
            });
        },
	
	/*
	 *
	 */
	this.saveAccount = function() {
	    var item = new Object();
            item['email'] = $("#account_form_email").val();
            item['name'] = $("#account_form_name").val();
            item['phone'] = $("#account_form_phone").val();
            item['address'] = $("#account_form_address").val();
            item['gender'] = $("#account_form_gender").val();
            item['drive_length'] = $("#account_form_drive_length").val();
            item['drive_category'] = $("#account_form_drive_category").val();

            var action = $("#account_form_action").val();
            if (action == "edit") {
                item['id'] = $("#account_form_id").val();
                this.model.edit(item);

            } else if (action == "add") {
                this.model.add(item);
            } 
	},
	
	this.changeRole = function(e) {
            
            var str = "role_action_";
	    var id = $(e).attr('id').substr(str.length);
            var action = $(e).html();
	
            if (action == "add") {
                this.model.changeRole(id, "delete", this.view.delRole);
            }
            
            if (action == "delete") {
                this.model.changeRole(id, "add", this.view.addRole);
            }
            
        }
	
}

